/**
 * @file ArticleAction.java
 * @brief ArticleAction Source 파일
 */

/**
 * @brief com.ryun.action
 */
package com.ryun.action;

import java.util.ArrayList;

import com.commons.action.BaseAction;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.SortDirection;
import com.ryun.bean.BoardBean;
import com.ryun.service.ArticleSvc;

@SuppressWarnings("serial")
public class ArticleAction extends BaseAction{
	public BoardBean boardBean = new BoardBean();
	public ArrayList<BoardBean> list = new ArrayList<BoardBean>();
	
	private ArticleSvc articleSvc;
	
	public Object getModel(){
		return boardBean;
	}
	public String insertForm() throws Exception{
		if(!userBean.isLogin()){
			return LOGIN;
		}
		return SUCCESS;
	}
	public String insert() throws Exception{
		Entity article = new Entity("article_free");
		article.setProperty("Title", boardBean.getTitle());
		article.setProperty("Content", boardBean.getContent());
		article.setProperty("RegDate", date);
		article.setProperty("User", user);

		articleSvc.insert(article);
		
		return SUCCESS;
	}
	public String list() throws Exception{
		Query query = new Query(boardBean.getType());
		//query.addFilter("Title", Query.FilterOperator.EQUAL, "keyword");
		query.addSort("RegDate", SortDirection.DESCENDING);

		list = articleSvc.list(query);
		
		return SUCCESS;
	}
	
	/**
	 * @brief 
	 * @return the articleSvc
	 */
	public ArticleSvc getArticleSvc() {
		return articleSvc;
	}
	/**
	 * @brief 
	 * @param articleSvc the articleSvc to set
	 */
	public void setArticleSvc(ArticleSvc articleSvc) {
		this.articleSvc = articleSvc;
	}
}
